package genericAndInterface

import "fmt"

type ReadWrite interface {
	read(b []byte) (int, error)
	write(b []byte) (int, error)
}

type Float interface {
	~float32 | ~float64
}

type FloatReadWrite interface {
	~float32 | ~float64
	read(b []byte) (int, error)
	write(b []byte) (int, error)
}

// ReadWrite
type rw struct{}

func (rw) read(b []byte) (int, error) {
	fmt.Println("func (rw) read(b []byte) (int, error)")
	return 0, nil
}
func (rw) write(b []byte) (int, error) {
	fmt.Println("func (rw) write(b []byte) (int, error)")
	return 0, nil
}

func test1() {
	rw1 := rw{}
	rw1.read([]byte{})
	rw1.write([]byte{})
}

// Float
func FloatTest[F Float]() {
	var tmp1 F = 3.14
	fmt.Printf("func FloatGI[F %T] ()：%f\n", tmp1, tmp1)
}
func test2() {
	type myFloat float32
	FloatTest[myFloat]()

	type youFloat float64
	FloatTest[youFloat]()
}

// FloatReadWrite
type myfloatRW1 float64

func (myfloatRW1) read(b []byte) (int, error) {
	fmt.Println("func (floatReadWrite1) read(b []byte) (int, error)")
	return 0, nil
}
func (myfloatRW1) write(b []byte) (int, error) {
	fmt.Println("func (floatReadWrite1) write(b []byte) (int, error)")
	return 0, nil
}

type myfloatRW2 float32

func (myfloatRW2) read(b []byte) (int, error) {
	fmt.Println("func (floatReadWrite2) read(b []byte) (int, error)")
	return 0, nil
}
func (myfloatRW2) write(b []byte) (int, error) {
	fmt.Println("func (floatReadWrite2) write(b []byte) (int, error)")
	return 0, nil
}
func FloatReadWriteTest[T FloatReadWrite]() {
	//var var1 T = make()
	//fmt.Printf("FloatReadWriteTest[T %T]()\n", var1)
	//var var2 T
	//fmt.Printf("FloatReadWriteTest[T %T]()\n", var2)

	var test T
	fmt.Printf("func FloatReadWriteTest[%T]()\n", test)
}
func test3() {
	//tmp1 := floatReadWrite1{}
	//tmp1.read([]byte{})
	//tmp2 := floatReadWrite2{}
	//tmp2.read([]byte{})

	FloatReadWriteTest[myfloatRW1]()
	FloatReadWriteTest[myfloatRW2]()
}

// test function
func GenericItf() {
	test1()
	test2()
	test3()
}
